﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HRC.Library.ContextFoundation;
using Lehnet.BusinessLayer;
using Lehnet.BusinessLayer.Interfaces;
using Lehnet.Models;
using Lehnet.WebUI.CustomAttributes;

namespace Lehnet.WebUI.Controllers
{
    [PersonelAuthorize]
    public class NakliyeciController : Controller
    {
        //
        // GET: /Nakliyeci/

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetAllNakliyecilerAjax()
        {
            var nb = ProxyHelper<NakliyeciBusiness, INakliyeciBusiness>.Instance.AddOrGet();
            List<Models.Nakliyeci> nakliyeciList = nb.LoadAll();
            JsonResult result = Json(nakliyeciList);
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return result;
        }

        public PartialViewResult Create(int? Id)
        {
            var m = new Nakliyeci();
            if (Id != null)
            {
                var nb = ProxyHelper<NakliyeciBusiness, INakliyeciBusiness>.Instance.AddOrGet();
                m = nb.LoadNakliyeciById((int)Id);
            }
            return PartialView(m);
        }
        [HttpPost]
        public PartialViewResult Create(Nakliyeci nakliyeci)
        {
            var nb = ProxyHelper<NakliyeciBusiness, INakliyeciBusiness>.Instance.AddOrGet();
            try
            {
                nb.SaveOrUpdate(nakliyeci);
            }
            catch (Exception exp)
            {
                throw exp;
            }
            return PartialView();
        }
        public JsonResult DeleteNakliyeciAjax(int nakliyeciId)
        {
            var nb = ProxyHelper<NakliyeciBusiness, INakliyeciBusiness>.Instance.AddOrGet();
            nb.Delete(nakliyeciId);
            JsonResult result = Json("Oldu, çok da güzel oldu!");
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return result;
        }
    }
}
